/* -----------------------------------------------------------------------
 * Author Daniel Pflieger
 * The following test determines if the score is counted correctly.
 *
 * testUpdateCoins: testUpdateCoins.c dominion.o rngs.o  test
 *      gcc -o testUpdateCoins -g  testUpdateCoins.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
  int i;
  int seed = 1000;
  int numPlayer = 2;
  int maxBonus = 10;
  int p, r, handCount;
  int bonus;
  int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
  int score;
     
 
  struct gameState G;
  int maxHandCount = 5;
  // arrays of all coppers, silvers, and golds
  int coppers[MAX_HAND];
  int silvers[MAX_HAND];
  int golds[MAX_HAND];
  
  int curses[MAX_HAND];
  int estates[MAX_HAND];
  int duchies[MAX_HAND];
  int provinces[MAX_HAND];
  int gardensA[MAX_HAND];
  // values of the arrays
  int curseCard = -1, estateCard = 1, duchyCard = 3, provinceCard = 6, gardenCard = 1;
  
  //initalize the cards
  for (i = 0; i < MAX_HAND; i++)
    {
      coppers[i] = copper;
      silvers[i] = silver;
      golds[i] = gold;
      
      curses[i] = curse;
      estates[i] = estate;
      duchies[i] = duchy;
      provinces[i] = province;
      gardensA[i] = gardens;
    }

  printf ("TESTING updateCoins():\n");
  for (p = 0; p < numPlayer; p++)
    {
      for (handCount = 0; handCount <= maxHandCount; handCount++)
        {
          
#if (NOISY_TEST == 1)
	  printf("Testing Curse Cards");
#endif
	  memset(&G, 23, sizeof(struct gameState));   // clear the game state
	  r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	  G.handCount[p] = handCount;                 // set the number of cards on hand
	  memcpy(G.hand[p], curses, sizeof(int) * handCount); // set all the cards to curses
	  score = scoreFor(p,&G);
#if(NOISY_TEST ==1)
	  printf("Expected Score with %d Curse cards %d, Received Score with %d Curse Cards %d \n",handCount, handCount*curseCard, handCount, score );
#endif
	  assert(score == handCount * curseCard);



#if (NOISY_TEST == 1)
	  printf("\nTesting Estate Cards");
#endif	
	  memset(&G, 23, sizeof(struct gameState));   // clear the game state
	  r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	  G.handCount[p] = handCount;                 // set the number of cards on hand
	  memcpy(G.hand[p], estates, sizeof(int) * handCount); // set all the cards to curses
	  score = scoreFor(p,&G);
#if(NOISY_TEST ==1)
	  printf("Expected Score with %d Estate cards %d, Received Score with %d Estate Cards %d \n",handCount, handCount*estateCard, handCount, score );
#endif
	  assert(score == handCount * estateCard);     


#if (NOISY_TEST == 1)
	  printf("\nTesting Duchy Cards");
#endif	
	  memset(&G, 23, sizeof(struct gameState));   // clear the game state
	  r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	  G.handCount[p] = handCount;                 // set the number of cards on hand
	  memcpy(G.hand[p], duchies, sizeof(int) * handCount); // set all the cards to curses
	  score = scoreFor(p,&G);
#if(NOISY_TEST ==1)
	  printf("Expected Score with %d Estate cards %d, Received Score with %d Estate Cards %d \n",handCount, handCount*duchyCard, handCount, score );
#endif
	  assert(score == handCount * duchyCard);     


#if (NOISY_TEST == 1)
	  printf("\nTesting Provence Cards");
#endif	
	  memset(&G, 23, sizeof(struct gameState));   // clear the game state
	  r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
	  G.handCount[p] = handCount;                 // set the number of cards on hand
	  memcpy(G.hand[p], provinces, sizeof(int) * handCount); // set all the cards to curses
	  score = scoreFor(p,&G);
#if(NOISY_TEST ==1)
	  printf("Expected Score with %d Estate cards %d, Received Score with %d Estate Cards %d \n",handCount, handCount*provinceCard, handCount, score );
#endif
	  assert(score == handCount * provinceCard);     
	
        }
    }

  printf("All tests passed!\n");

  //I would test the Gardens card, but the province card would require more complicated coding and would probably be better to test
  // during random coding, since the value of the garden card depends on more random values. Since these assertions seem to work
  // I would say that waiting is a good idea. 





  return 0;
}
